﻿CREATE TABLE [dbo].[DealOrderDetails] (
    [ID]              INT             IDENTITY (1, 1) NOT NULL,
    [OID]             INT             NOT NULL,
    [ProductID]       INT             NOT NULL,
    [MaterialID]      INT             NOT NULL,
    [ProcessID]       INT             NOT NULL,
    [Size]            VARCHAR (50)    CONSTRAINT [DF_DealOrderDetails_Size] DEFAULT ('无') NOT NULL,
    [Quantity]        DECIMAL (18, 5) NOT NULL,
    [UnitPrice]       DECIMAL (18, 5) NOT NULL,
    [WeightQuantity]  DECIMAL (18, 5) CONSTRAINT [DF_DealOrderDetails_WeightQuantity] DEFAULT ((0)) NOT NULL,
    [WeightUnitPrice] DECIMAL (18, 5) CONSTRAINT [DF_DealOrderDetails_WeightUnitPrice] DEFAULT ((0)) NOT NULL,
    [Money]           DECIMAL (18, 5) NOT NULL,
    CONSTRAINT [PK_order_deal_details_ID] PRIMARY KEY CLUSTERED ([ID] ASC),
    CONSTRAINT [FK_DealOrderDetails_ProductMaterials] FOREIGN KEY ([MaterialID]) REFERENCES [dbo].[ProductMaterials] ([ID]),
    CONSTRAINT [FK_DealOrderDetails_ProductProcesses] FOREIGN KEY ([ProcessID]) REFERENCES [dbo].[ProductProcesses] ([ID]),
    CONSTRAINT [FK_order_deal_details_order_deal] FOREIGN KEY ([OID]) REFERENCES [dbo].[DealOrders] ([ID]) ON DELETE CASCADE,
    CONSTRAINT [FK_order_deal_details_products] FOREIGN KEY ([ProductID]) REFERENCES [dbo].[Products] ([ID])
);

